package com.mass.core.ueditor.controller;

import com.mass.core.ueditor.ActionEnter;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author: hobbesgo
 * @Description:
 * @Date: 创建于 14:54 2018/1/11 0011
 * @Modified By:
 */
@Controller
public class UEditorController {

    @Value("${ueditor.upload-path}")
    private String basePath;    //上传文件路径
    
    @Value("${server.context-path}")
	private String projectName;   //项目前缀

    
    @RequestMapping(value="/config")
    public void config(HttpServletRequest request, HttpServletResponse response) throws Exception {
        response.setContentType("application/json");
        String rootPath = request.getSession().getServletContext().getRealPath("/");
        try {
            String exec = new ActionEnter(request, rootPath,basePath.replaceAll("\\\\",""),projectName).exec();
            PrintWriter writer = response.getWriter();
            writer.write(exec);
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
